package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.CommonResult;
import com.atguigu.eduservice.entity.EduSubject;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 李红磊
 * @since 2021-06-11
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;


    @PostMapping("addSubject")
    public CommonResult addSubject(MultipartFile file) {
        System.out.println("进入到addSubject");
        subjectService.saveSubject(file, subjectService);
        return CommonResult.ok();
    }

    //课程分类返回结构(树形)
    @GetMapping("getAllSubject")
    public CommonResult getAllSubject() {
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return CommonResult.ok().data("list", list).data("test","嗯嗯嗯");
    }


    //根据一级下拉框的change事件完成二级下拉框的铺垫
    @GetMapping("levelTwo/{id}")
    public CommonResult levelTwo(@PathVariable("id") String subjectParentId){
        System.out.println("请求打到这里");
        List<EduSubject> list=subjectService.getLevelTwo(subjectParentId);
        return CommonResult.ok().data("list",list);
    }


}

